#ifndef ISLANDAPP_H
#define ISLANDAPP_H

#include "DXApp.h"
#include "Camera.h"
#include "Light.h"

#include "Bottle.h"
#include "Globe.h"
#include "Island.h"
#include "Sea.h"
#include "Tree.h"

#include "FireSystem.h"

//#include <xnamath.h>
#include <d3dx11Effect.h>
#include <string>

using std::string;


struct Params
{
	int topX;
	int topY;
	int width;
	int height;
	
	string file_globe;
	string file_sea;
	string file_island;
	string file_tree;
	string file_bottle;

	int _shadow_texture;

	Light_Params		directional;
	Light_Params		spot[4];
};


enum  { SPRING, SUMMER, AUTUMN, WINTER };
enum ViewMode { VIEW_GLOBE, VIEW_TREE, VIEW_LEAVES, VIEW_BOTTLE, VIEW_SEA };

class IslandApp : public DXApp
{
	public:
		IslandApp();
		~IslandApp();

		int run();
		bool initialise(HINSTANCE hInstance, int cmdShow);

		HRESULT buildFX();
		HRESULT buildGeometry();

		void renderScene(float dt);
		void updateScene();

		void onKey(WPARAM key_code);

		void renderQuad();

		void setViewMode(ViewMode mode);
		
		void onMouseWheel(WPARAM wParam);
		void onLMouseClick(LPARAM lParam);
		void onRMouseClick(LPARAM lParam);
		void onLMouseDrag(int oldX, int oldY, int newX, int newY);

		FireSystem*		fireSystem;

		Camera* getCamera() { return &camera; }
		void updateViewMode();
	private:
		
		ViewMode	m_ViewMode;

		bool mEditMode;

		float sim_speed;
		bool bEnd;

		unsigned int _season;
		unsigned int  _day;

		// in seconds 
		float day_time;
		float season_time;
		// in seconds
		float day_length;
		float season_length;


		Camera camera;
		Light directional;
		Light spotlights[4];

		std::vector<Light*> _lights;

		Params _params;

		ID3DX11Effect*			fx;
		ID3DX11Effect*			fx_shadow;
		ID3DX11Effect*			fx_quad;
		ID3DX11Effect*			fx_fireCollision;


		ID3D11InputLayout*		input_layout;
		ID3D11Buffer*				vb_quad;

		float dt;
		// World
		Bottle _bottle;
		Island _island;
		Tree   _tree;
		Globe  _globe;
		Sea	   _sea;


		//--------------

		

		// GUI
		

		void bindRtvDsv();
		void updateLights(float dt);
		void createInputLayout();
		void createLights();
		void readConfigFile();
		void initGUI();
		//////////////////////////////////////////////////////////////////////////
};


#endif